package com.song.JavaThread_day07.ch7_10;

import java.util.concurrent.TimeUnit;

public class Main {
	
	
	public static void main(String[] args) {
		
		MyPriorityTransferQueue<Event> buffer = new MyPriorityTransferQueue<Event>();
		
		Producer producer = new Producer(buffer);
		Thread pthread[] =  new Thread[10];
		for(int i=0;i<pthread.length;i++)
		{
			pthread[i] = new Thread(producer);
			pthread[i].start();
		}
		
		Consumer consumer = new Consumer(buffer);
		Thread cthread = new Thread(consumer);
		cthread.start();
		
		System.out.printf(" Main : Buffer : Consumer count : %d \n",buffer.getWaitingConsumerCount());
		
		Event myevent = new Event(" Core Event" ,0);
		try {
			buffer.transfer(myevent);
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.printf("Main : My Event has Been Transfered \n");
		
		for(int i=0;i<pthread.length;i++)
		{
			try {
				pthread[i].join();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.printf(" Main : Buffer : Consumer count : %d \n",buffer.getWaitingConsumerCount());
		
		
		myevent = new Event(" Core Event 2", 0);
		try {
			buffer.transfer(myevent);
			cthread.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.printf(" Main : End of the program \n");
		
	}
}
